#include "D20CharacterItem.h"



namespace
{
QString CAMPAIGN_FIELD_NAME = "campaign";
}

D20CharacterItem::D20CharacterItem(QObject *parent) :
    RootItem(parent)
{
}



D20CharacterItem::D20CharacterItem(const QString &name, QObject *parent)
    : RootItem(name, parent)
{
}



D20CharacterItem::~D20CharacterItem()
{
}


QString D20CharacterItem::campaignFile() const
{
    return data(CampaignData, Qt::EditRole).toString();
}



int D20CharacterItem::fieldCount() const
{
    return (D20CharacterItem::DataType_LAST - AbstractItem::DataType_FIRST + 1);
}



QString D20CharacterItem::fieldName(const int &data_type) const
{
    QString name = RootItem::fieldName(data_type);
    if (!name.isEmpty()) return name;

    switch (data_type)
    {
    case CampaignData:  return CAMPAIGN_FIELD_NAME;
    default:            return QString::null;
    }
}



int D20CharacterItem::field(const QString &field_name) const
{
    if (field_name == CAMPAIGN_FIELD_NAME) return CampaignData;

    return RootItem::field(field_name);
}



void D20CharacterItem::setCustomData(const int &data_type, const QVariant &value)
{
    switch (data_type)
    {
    case CampaignData:
        m_campaignFile = value.toString();
        return;
    }

    RootItem::setCustomData(data_type, value);
}



QVariant D20CharacterItem::customData(const int &data_type, int role) const
{
    if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();

    switch (data_type)
    {
    case CampaignData:
        return m_campaignFile;
    }

    return RootItem::customData(data_type, role);

}


